description: A rendered UI component (markdown or HTML).
The ${lua expression} syntax can be used to implement custom widgets. If the Lua expression evaluates to a simple string, it will live preview as that string rendered as markdown. However, if the expression returns a widget.new-generated result value, you can do some fancier stuff.
To render a widget, call widget.new with any of the following keys:
markdown: Renders the value as markdownhtml: Renders an HTML string or DOM element as a widgetdisplay: Render the value either inline or as a block (defaults to inline)cssClasses: Array of CSS class names to add to the widget containerFor common cases, use these shortcuts instead of widget.new directly:
| Function | Description |
|---|---|
widget.markdown(md) |
Inline markdown widget |
widget.markdownBlock(md) |
Block-level markdown widget |
widget.html(html) |
Inline HTML widget |
widget.htmlBlock(html) |
Block-level HTML widget |
The simplest widget type renders markdown:
${widget.markdown("**Bold** and *italic* text")}
For block-level content (like lists or tables), use widget.markdownBlock:
${widget.markdownBlock("## A heading\n* Item 1\n* Item 2")
For full control over the rendered output, use HTML widgets with the Space Lua/DOM|DOM builder API:
function marquee(text)
return widget.html(dom.marquee {
class = "my-marquee",
onclick = function()
editor.flashNotification "You clicked me"
end,
text
})
end
We can combine this with some Space Style to style it:
.my-marquee {
color: purple;
}
Now, let's use it (try clicking): ${marquee "Finally, marqeeeeeee!"}
The standard library provides several pre-built widgets in the widgets table:
widgets.button(text, callback) — a simple button that runs the callback when clickedwidgets.commandButton(commandName) — a button for a command (button text is the command name)widgets.commandButton(text, commandName) — a button for a command with custom textwidgets.commandButton(text, commandName, args) — a button for a command with argumentsExample: ${widgets.button("Hello", function() editor.flashNotification "Hi there!" end)}
${widgets.commandButton("System: Reload")}
widgets.subPages(pageName?) — renders a list of sub-pages (pages with the given prefix). Defaults to the current page.These render automatically on every page and can be configured:
Configure them in your ^Library/Std/Config page:
-- Disable TOC altogether
config.set("std.widgets.toc.enabled", false)
-- Only render a TOC when there's >= 5 headers
config.set("std.widgets.toc.minHeaders", 5)
-- Disable linked mentions
config.set("std.widgets.linkedMentions.enabled", false)
-- Disable linked tasks
config.set("std.widgets.linkedTasks.enabled", false)
The embed namespace provides widgets for embedding external content:
embed.youtube(url) — embeds a YouTube videoembed.peertube(url) — embeds a PeerTube videoembed.vimeo(url) — embeds a Vimeo videoYou can add your own widgets to the top or bottom of every page by listening to the rendering events:
event.listen {
name = "hooks:renderTopWidgets",
run = function(e)
return widget.new {
markdown = "This appears at the top of every page!"
}
end
}
See also: Space Lua/DOM, API/widget, API/dom